 package server.console.groups.update;






 import com.alee.extended.window.WebProgressDialog;
 import com.alee.laf.button.WebButton;
 import com.alee.laf.label.WebLabel;
 import com.alee.laf.list.WebList;
 import com.alee.laf.list.WebListModel;
 import com.alee.laf.optionpane.WebOptionPane;
 import com.alee.laf.panel.WebPanel;
 import com.alee.laf.rootpane.WebDialog;
 import com.alee.laf.rootpane.WebFrame;

         import com.alee.laf.text.WebTextPane;
 import com.alee.managers.notification.WebNotification;
 import com.alee.utils.FileUtils;
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Frame;





         import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import javax.swing.ListModel;
 import javax.swing.SwingWorker;


         import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;



 public class UpdateServer extends WebDialog {
/*  48 */   private static final Logger log = LogManager.getLogger();
/*  49 */   private static final WebLabel lasttimes = new WebLabel();
/*  50 */   private static final WebList patchList = new WebList((ListModel)new WebListModel());
/*  51 */   private static final List<String> patchListData = new ArrayList<>();
   private static UpdateServer instance;
   private static Map<String, Map<String, String>> versions;
   private static boolean findnewver;
/*  55 */   private final WebTextPane patchLog = new WebTextPane();
/*  56 */   private final WebButton updateNow = new WebButton();
/*  57 */   private final WebLabel newverlabel2 = new WebLabel();




/*  62 */   private String toversion = getNewVersion();

   private WebButton updateTo;

   public UpdateServer(WebFrame owner) {
/*  67 */     super((Frame)owner, "检查服务端更新", true);
     setLasttimes("");
/*  69 */     setPreferredSize(new Dimension(800, 600));
/*  70 */     add((Component)new WebPanel(new BorderLayout(5, 5))
         {

         });




















































































/* 158 */     patchList.setSelectedIndex(0);
   }

   public static UpdateServer getInstance(WebFrame owner) {
/* 162 */     if (instance == null) {
/* 163 */       instance = new UpdateServer(owner);
     }
/* 165 */     return instance;
   }

   public static String getNewVersion() {
/* 169 */     List<String> verlist = new ArrayList<>(versions.keySet());
/* 170 */     verlist.sort((o1, o2) -> {
           String[] split1 = o1.split("\\.");
           String[] split2 = o2.split("\\.");
           for (int i = 0; i < 3; i++) {
             int n1 = Integer.parseInt(split1[i]);
             int n2 = Integer.parseInt(split2[i]);
             if (n1 > n2) {
               return -1;
             }
             if (n1 < n2)
               return 1;
           }
           return 0;
         });
/* 184 */     return (verlist.size() > 0) ? verlist.get(0) : "1.0.0";
   }

   public void setLasttimes(String lasttime) {
/* 188 */     lasttimes.setText("最后检查更新时间：" + lasttime);
   }

   public void updateNewVerLabel() {
/* 192 */     if (findnewver) {
/* 193 */       this.newverlabel2.setText(getNewVersion() + " new!");
/* 194 */       this.newverlabel2.setForeground(Color.RED);
/* 195 */       this.updateNow.setText("立即更新");
     } else {
/* 197 */       this.newverlabel2.setText("已经是最新");
/* 198 */       this.updateNow.setText("检查更新");
     }
   }

   public void downUpdate() {
/* 203 */     (new SwingWorker<Object, Object>()
       {
         protected Object doInBackground() throws Exception {
/* 206 */           UpdateServer.this.updateNow.setEnabled(false);
/* 207 */           UpdateServer.this.updateTo.setEnabled(false);
/* 208 */           FileUtils.clearDirectory(new File("update_temp"));
/* 209 */           WebProgressDialog progressDialog = new WebProgressDialog("下载更新");
/* 210 */           progressDialog.setDefaultCloseOperation(0);
/* 211 */           progressDialog.setPreferredProgressWidth(300);
/* 212 */           progressDialog.setVisible(true);
/* 213 */           progressDialog.setAlwaysOnTop(true);
/* 214 */           progressDialog.setText("正在下载更新包 v." + UpdateServer.this.toversion + "……");
           try {
/* 216 */             URL url = new URL("http://114.215.69.243/patchs/" + UpdateServer.this.toversion + "/Server.jar");
/* 217 */             URLConnection connection = url.openConnection();
/* 218 */             try (InputStream inputStream = connection.getInputStream()) {
/* 219 */               File file = new File("update_temp\\Server.jar");
/* 220 */               File dir = new File("update_temp");
/* 221 */               if (!dir.exists()) {
/* 222 */                 dir.mkdirs();
               }
/* 224 */               try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
/* 225 */                 byte[] buff = new byte[1024];

/* 227 */                 int total = 0; int len;
/* 228 */                 while ((len = inputStream.read(buff)) != -1) {
/* 229 */                   fileOutputStream.write(buff, 0, len);
/* 230 */                   total += len;
/* 231 */                   progressDialog.setProgress((int)(total / connection.getContentLength() * 100.0D));
                 }
               }
             }
/* 235 */           } catch (IOException e) {
/* 236 */             WebOptionPane.showMessageDialog((Component)UpdateServer.this, "连接更新服务器失败，请稍后重试");
/* 237 */             return null;
           } finally {
/* 239 */             progressDialog.dispose();
/* 240 */             UpdateServer.this.updateNow.setEnabled(true);
/* 241 */             UpdateServer.this.updateTo.setEnabled(true);
           }
/* 243 */           if (Boolean.valueOf((String)((Map)UpdateServer.versions.get(UpdateServer.this.toversion)).get("reload")).booleanValue()) {
/* 244 */             makeReloadFile();
           }
/* 246 */           WebOptionPane.showMessageDialog((Component)UpdateServer.this, "更新完成，请手动重启服务端。\r\n若选择的版本错误，可重新选择版本并更新即可。");
/* 247 */           return null;
         }

         private void makeReloadFile() {
/* 251 */           File file = new File("update_temp\\update.ini");
/* 252 */           try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
/* 253 */             fileOutputStream.write(1);
/* 254 */           } catch (IOException e) {
/* 255 */             UpdateServer.log.error("创建更新配置文件错误", e);
           }
         }
/* 258 */       }).execute();
   }

   public static class CheckUpdateRun implements Runnable {
     private static WebNotification notification;
     private static boolean running = false;

     public void run() {}
   }
 }


/* Location:              C:\PGX\Server.jar!\server\console\group\\update\UpdateServer.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */